from typing import Type, Generic, TypeVar, Any, Optional,List
from sqlalchemy import Select, func, select
from sqlalchemy.ext.asyncio import AsyncSession
from pydantic import BaseModel,Field

T = TypeVar("T", bound=BaseModel)  # Pydantic响应模型
M = TypeVar("M")  # SQLAlchemy 模型

class PaginationMeta(BaseModel):
    """分页元数据"""
    page: int = Field(..., description="当前页码")
    page_size: int = Field(..., description="每页数量")
    total_items: int = Field(..., description="总记录数")
    total_pages: int = Field(..., description="总页数")


class PaginatedResponse(BaseModel, Generic[T]):
    """分页响应模型"""
    data: List[T] = Field(..., description="数据列表")
    pagination: PaginationMeta = Field(..., description="分页元数据")

    class Config:
        json_schema_extra = {
            # "example": {
            #     "data": [],
            #     "pagination": {
            #         "page": 1,
            #         "page_size": 10,
            #         "total_items": 0,
            #         "total_pages": 0,
            #         "list":[]
            #     }
            # }
            "example": {
                "page": 1,
                "page_size": 10,
                "total_items": 0,
                "total_pages": 0,
                "list": [],
            }
        }
        




